<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Unit1 extends Page
{
       public $hiddenEmp = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $dpLicense = null;
       public $edOpClass = null;
       public $edLicNum = null;
       public $JTSiteTheme1 = null;
       public $Label3 = null;
       public $Label2 = null;
       public $Label1 = null;
       public $Image3 = null;
       function btnCancelClick($sender, $params)
       {
       redirect('personnel_list.php?emp='.$this->hiddenEmp->getValue());


       }

       function Unit1Create($sender, $params)
       {
       $emp = $_GET['emp'];
       $this->hiddenEmp->setValue($emp);

       $result_license = mysql_query("select * from emp_license_tbl where emp_id='".$this->hiddenEmp->getValue()."'");
       $row_license = mysql_fetch_array($result_license);

       $this->edLicNum->Text=$row_license['license_num'];
       $this->edOpClass->Text=$row_license['op_class'];
       $this->dpLicense->Date=$row_license['license_renew_date'];

       }

       function btnSubmitClick($sender, $params)
       {

      $result_license = mysql_query("select * from emp_license_tbl where emp_id='" . $this->hiddenEmp->getValue(). "'");
      $license_count = mysql_num_rows($result_license);
      if($license_count == 0)
      {
      $result = mysql_query("insert into emp_license_tbl (company_id,
       emp_id,
       license_num,
       op_class,
       license_renew_date)

       values ('".$_SESSION['company_id']."',
       '".$this->hiddenEmp->getValue()."',
       '".$this->edLicNum->Text."',
       '".$this->edOpClass->Text."',
       '".$this->dpLicense->Date."')");
       }
       else
       {
       mysql_query("update emp_license_tbl set
       license_num = '".$this->edLicNum->Text."',
       op_class = '".$this->edOpClass->Text."',
       license_renew_date = '".$this->dpLicense->Date."'
       where emp_id='".$this->hiddenEmp->getValue()."'")or die(mysql_error());
       }

       redirect('personnel_list.php?emp='.$this->hiddenEmp->getValue());


       }

}

global $application;

global $Unit1;

//Creates the form
$Unit1=new Unit1($application);

//Read from resource file
$Unit1->loadResource(__FILE__);

//Shows the form
$Unit1->show();

?>